package com.example.panda;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.panda.adapter.SquareAdapter;
import com.example.panda.fragment.FocusFragment;
import com.example.panda.fragment.TuijianFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class SquareActivity extends AppCompatActivity {

    public SquareActivity() {
    }

    private ViewPager viewpager;
    private TabLayout tabLayout;
    private List<Fragment> squarefragmentList=new ArrayList<>();
    private List<String> list_title=new ArrayList<>();
    private SquareAdapter mySquareAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.square);
        getFragment();
        getTilte();
        initView();
    }

    private void getFragment(){
        Fragment tuijianFragment=new TuijianFragment();
        squarefragmentList.add(tuijianFragment);
        Fragment focusFragment=new FocusFragment();
        squarefragmentList.add(focusFragment);
    }

    private void getTilte(){
        list_title.add(getString(R.string.tuijian));
        list_title.add(getString(R.string.focus));
    }

    private void initView(){
        tabLayout=findViewById(R.id.tablayout);
        viewpager=findViewById(R.id.viewpager);
        mySquareAdapter=new SquareAdapter(getSupportFragmentManager(),squarefragmentList,list_title);
        viewpager.setAdapter(mySquareAdapter);
        for (int i=0;i<list_title.size();i++){
            tabLayout.addTab(tabLayout.newTab().setText(list_title.get(i)));
        }
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

        tabLayout.setupWithViewPager(viewpager);
    }
}
